<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
	<title>工勿忧</title>
	<link rel="stylesheet" type="text/css" href="../../../css/api.css" />
	<link rel="stylesheet" type="text/css" href="../../../css/hui.css" />
	<link rel="stylesheet" type="text/css" href="../../../css/iconfont.css" />
</head>

<body>
<style>
#health{width:100%}
#health li{float:left;text-align:center;height:36px;line-height:36px;background-color:#7BCAFF;}

</style>
	<div style="padding:0px;margin:0px;">
		<ul id="health">
			
		</ul>
	</div>
	<div id="container" style="width:100%; height:100%; margin: 0 auto"></div>
	
</body>

</html>
<script src="../../../script/hui.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../script/hui-tab.js" type="text/javascript"></script>
<script src="../../../script/api.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../script/stm.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../script/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../script/highcharts.js" type="text/javascript" charset="utf-8"></script>

<script type="text/javascript">

	apiready = function () {

		$api.setStorage('healthnum',0)
		if($api.getStorage('health')!='' && $api.getStorage('health')!=null){
			var health = $api.getStorage('health')+'';
		}else{
			var health = '血压,血脂,血糖,慢性肺阻';
		}
		var healthArr = health.split(",")
		var html = '';
		var width = 100/healthArr.length
		$api.setStorage('healthnum',healthArr.length)

		for(i=0;i<healthArr.length;i++){
			var bg = '';
			if(i==0){ bg = '#4DB8FF'; }
			html += "<li id='t_"+i+"' onclick=tab('"+healthArr[i]+"',"+i+") style='width:"+width+"%;background-color:"+bg+"'>"+healthArr[i]+"</li>"
		}
		hui("#health").html(html)
		xueya()

	}

	hui('#hui-header-menu').click(function () {
		hui.actionSheet(menus, cancel, function (e) {
			console.log(e.index);
			hui.toast(e.innerHTML);
		});
	});

	function tab(n,i) {

		var num = $api.getStorage('healthnum')
		for(a=0;a<num;a++){
			if (i==a) {
				document.getElementById("t_"+i).style.backgroundColor = "#4DB8FF";
			} else {
				document.getElementById("t_"+a).style.backgroundColor = "#7BCAFF";
			}
		}
		
		if(n=='血压'){
			xueya()
		}else if(n=='血脂'){
			xuezhi()
		}else if(n=='血糖'){
			xuetang()
		}else if(n=='慢性肺阻'){
			manxingfeizu()
		}

	}

	
	
	function xueya(){
		console.log("血压")	
		getdata('血压上报数据曲线图','最近10次记录','血压')
	}

	function xuetang(){
		console.log("血糖")	
		getdata('血糖上报数据曲线图','最近10次记录','血糖')
	}

	function xuezhi(){
		console.log("血脂")	
		getdata('血脂上报数据曲线图','最近10次记录','血脂')
	}

	function manxingfeizu(){
		console.log("慢性肺阻")	
		getdata('慢性肺阻上报数据曲线图','最近10次记录','慢性肺阻')
	}


	function getdata(title,text,type){

		api.ajax({
			url: $api.getStorage('geturl')+'&c=ajaxmember&a=bydaydanger',
			method: 'post',
			data: {
				values: { 
					userid : $api.getStorage('userid'),
					docid  : $api.getStorage('docid'),
					hospid : $api.getStorage('hospid'),
					type   : type,
				}
			}
		},function(ret, err){
			if (ret) {
				var title= title;
				var text = text;
				var data = ret.data;
				console.log(JSON.stringify(ret));		
				getcont(title,text,data)
			} else {
				alert( JSON.stringify( err ) );
			}
		});
	}

	function getcont(txt1,txt2,data){

		$("#container").height(api.frameHeight-40)
		var title = {
			text: txt1
		};
		var subtitle = {
			text: txt2
		};
		var credits = {
			enabled: false
		};
		var xAxis = { categories:['1','2','3','4','5','6','7','8','9','10'] };
		
		var yAxis = {
			title: {
				text: ''
			}

		};
		var plotOptions = {
			line: {
				dataLabels: {
					enabled: true
				},
				enableMouseTracking: false
			}
		};
		var series = data;

		var json = {};

		json.title = title;
		json.subtitle = subtitle;
		json.credits = credits;
		json.xAxis = xAxis;
		json.yAxis = yAxis;
		json.series = series;
		json.plotOptions = plotOptions;
		$('#container').highcharts(json);

	}

	


</script>